package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * 为了商品详情页面渲染并跳转的类
 *
 */
@Controller
public class ItemController {


    @Autowired
    private ItemFeignClient itemFeignClient;

    //进入的商品详情页面
    @GetMapping("{skuId}.html")
    public String index(@PathVariable(name = "skuId") Long skuId, Model model){
        //数据汇总
        Result<Map> result = itemFeignClient.getSkuInfoBySkuId(skuId);
        //将整合Map放到Request域中
        // Map  k: price  v:5688
        // request.setAttribute(price,5688)
        // request.setAttribute(skuInfo,5688)
        model.addAllAttributes(result.getData());
        return "item/index";
    }


}
